#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;

const int N=2e5+10;

struct node{
    int l,r;
    int tmax;
}tr[N * 4];
int m,p;
char op[2];

void pushup(int u)
{
    tr[u].tmax=max(tr[u<<1].tmax,tr[u<<1|1].tmax);
}

void build(int u,int l,int r)
{
    if(l == r) tr[u]={l,r};
    else
    {
        tr[u]={l,r};
        int mid=l+r>>1;
        build(u<<1,l,mid),build(u<<1|1,mid+1,r);
    }
}

int query(int u,int l,int r)
{
    int v=0;
    if(l <= tr[u].l && tr[u].r <= r) return tr[u].tmax;
    else
    {
        int mid=tr[u].l+tr[u].r>>1;
        if(l <= mid) v=query(u<<1,l,r);
        if(r > mid) v=max(v,query(u<<1|1,l,r));
    }
    return v;
}

void modify(int u,int x,int v)
{
    if(tr[u].l == x && tr[u].r == x) tr[u].tmax=v;
    else
    {
        int mid=tr[u].l+tr[u].r>>1;
        if(x<=mid) modify(u<<1,x,v);
        else modify(u<<1|1,x,v);
        pushup(u);
    }
}

int main()
{
    scanf("%d%d",&m,&p);

    build(1,1,m);

    int n=0,last=0,t;
    while(m--)
    {
        scanf("%s%d",op,&t);
        if(*op == 'Q')
        {
            last=query(1,n-t+1,n);
            printf("%d\n",last);
        }
        else
        {
            modify(1,++n,((long long)last+t)%p);
        }
    }
    return 0;
}
